#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
using namespace std;
typedef long long ll;
int n, tmp;
vector<int> nums;
vector<int> color;
int ans;
void dfs(int dep)
{
    if(dep == n)
    {
        int cnt = 0;
        for(int i = 0; i < nums.size(); i ++)
        {
            bool f = false;
            for(int j = i - 1; j >= 0; j --)
            {
                if(nums[i] == nums[j])
                {
                    f = true;
                    break;
                }
            }
            if(f)
            {
                for(int j = i - 1; j >= 0; j --)
                {
                    if(color[i] == color[j])
                    {
                        if(nums[i] == nums[j]) cnt += nums[j];
                        break;
                    }
                }
            }
        }
        ans = max(ans, cnt);
        return;
    }
    color.push_back(0);
    dfs(dep + 1);
    color.pop_back(), color.push_back(1);
    dfs(dep + 1);
    color.pop_back();
    return;
}
void solve()
{
    nums.clear(), color.clear(), ans = 0;
    cin >> n;
    for(int i = 0; i < n; i ++) cin >> tmp, nums.push_back(tmp);
    if(n <= 15) dfs(0), cout << ans << endl;
    else cout << 0 << endl;
    return;
}
int main()
{
    IOS;
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while(T --) solve();
    return 0;
}
